package com.qingyouchuxing.mall.biz.mapper;

import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryWrapper;
import com.qingyouchuxing.mall.biz.domain.entity.MallMailAddress;
import com.qingyouchuxing.mall.biz.domain.vo.MallMailAddressVO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;

import static com.qingyouchuxing.mall.biz.domain.entity.table.MallMailAddressTableDef.MALL_MAIL_ADDRESS;
@Mapper
public interface MallMailAddressMapper extends BaseMapper<MallMailAddress> {

    /**
     * 查询商品收货地址(集合)
     *
     * @param fkTenantId 租户ID
     * @param id         收货地址ID
     * @return
     */

    default List<MallMailAddressVO> selectMailAddressList(Long fkTenantId, Long id) {
        QueryWrapper queryWrapper = QueryWrapper.create().from(MALL_MAIL_ADDRESS)
            .where(MALL_MAIL_ADDRESS.ID.eq(id))
            .and(MALL_MAIL_ADDRESS.FK_TENANT_ID.eq(fkTenantId))
            .orderBy(MALL_MAIL_ADDRESS.CREATE_TIME.desc());
        return selectListByQueryAs(queryWrapper, MallMailAddressVO.class);
    }

    /**
     * 查询商品默认收货地址
     *
     * @param fkTenantId 租户ID
     * @return
     */

    default MallMailAddressVO selectMailAddressInfo(Long fkTenantId) {
        QueryWrapper queryWrapper = QueryWrapper.create().from(MALL_MAIL_ADDRESS)
            .where(MALL_MAIL_ADDRESS.FK_TENANT_ID.eq(fkTenantId))
            .and(MALL_MAIL_ADDRESS.DEFAULT_ADDRESS.eq(1))
            .orderBy(MALL_MAIL_ADDRESS.CREATE_TIME.desc());
        return selectOneByQueryAs(queryWrapper, MallMailAddressVO.class);
    }

    /**
     * 查询商品收货地址
     *
     * @param fkTenantId 租户ID
     * @param id         收货地址ID
     * @return
     */

    default MallMailAddressVO selectMailAddressById(Long fkTenantId, Long id) {
        QueryWrapper queryWrapper = QueryWrapper.create().from(MALL_MAIL_ADDRESS)
            .where(MALL_MAIL_ADDRESS.ID.eq(id))
            .and(MALL_MAIL_ADDRESS.FK_TENANT_ID.eq(fkTenantId))
            .orderBy(MALL_MAIL_ADDRESS.CREATE_TIME.desc());
        return selectOneByQueryAs(queryWrapper, MallMailAddressVO.class);
    }
}
